<html> 
   <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	 <title> WxConnect JSDK - redirectURI </title>
	 <style type="text/css">
		html, body{font-size:1rem; line-height:180%;}
	 </style>
	<script src="assets/js/jquery.min.js"></script>
   </head> 
   <body> 
	<div>
		<h3>数据传输中，请稍后...</h3>
	</div>
	<script type="text/javascript">
		function GetQueryString(name){
			/*定义正则，用于获取相应参数*/
		     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			 /*字符串截取，获取匹配参数值*/
		     var r = window.location.search.substr(1).match(reg);
			 /*但会参数值*/
		     if(r!=null)return  decodeURI(r[2]); return null;
		};
		if(GetQueryString("code") && GetQueryString("state")){//回调成功
			var code=GetQueryString("code");
			var state=GetQueryString("state");
			console.log(window.sessionStorage.getItem("random_num"));
//			window.location.href="https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx8110ffb151e28132&secret=717c1c51b9a0774e836e1163e219f831&code="+code+"&grant_type=authorization_code"
			$("body").append('<iframe src="https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx8110ffb151e28132&secret=717c1c51b9a0774e836e1163e219f831&code='+code+'&grant_type=authorization_code"></iframe>')
			console.log($("iframe"))
			console.log($("iframe")[2])
//			if(state==window.sessionStorage.getItem("random_num")){
//				$.get("https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx8110ffb151e28132&secret=717c1c51b9a0774e836e1163e219f831&code="+code+"&grant_type=authorization_code",function(data){
//					console.log(data)
//				});
//			}
//			window.location.href="login.html?code="+code+"&state="+state+""
		}else if(!GetQueryString("code") && GetQueryString("state")){
			console.log("用户禁止授权");
			window.location.href="login.html"
		}else{//可能遭遇攻击
			alert("系统错误");
		};
	</script>
   </body> 
</html>

